﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace OnlineManagement.Web.webs
{
    public class BasePage : System.Web.UI.Page
    {
        public int HoggeryId
        {
            get
            {
                int hoggeryId = 0;
                if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return hoggeryId;
                }
                FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                string hoggeryIdStr = id.Ticket.UserData;
                int.TryParse(hoggeryIdStr, out hoggeryId);
                return hoggeryId;
            }
        }

        private int _hoggeryId = 0;
        public string HoggeryName
        {
            get
            {
                try
                {
                    if (HttpContext.Current.User.Identity != null &&
                        !HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        return string.Empty;
                    }
                    string hoggeryName = Common.PubSessions.CacheHoggeryName;
                    if (string.IsNullOrEmpty(hoggeryName))
                    {
                        BLL.Dal.Hoggery bllHog = new BLL.Dal.Hoggery();
                        if (_hoggeryId == 0)
                        {
                            _hoggeryId = HoggeryId;
                        }
                        if (_hoggeryId != 0)
                        {
                            hoggeryName = bllHog.GetHoggeryName(_hoggeryId);
                            Common.PubSessions.CacheHoggeryName = hoggeryName;
                        }
                    }
                    return hoggeryName;
                }
                catch (Exception ex)
                {
                    log4net.ILog log = OnlineHoggeryLog.GetLog("BasePage.HoggeryName");
                    log.Error(new Com.HoggeryLog(), ex);
                    return string.Empty;
                }
            }
        }
    }
}